package com.nativetalk.service.teacher.search;

import com.nativetalk.base.Page;
import com.nativetalk.base.RetInfo;
import com.nativetalk.bean.TsNtCourseInfo;
import com.nativetalk.bean.comment.TdNtCommentCouse;
import com.nativetalk.bean.course.TdNtCoursePictureListUrl;
import com.nativetalk.bean.course.TsNtCourseInfoDetail;
import com.nativetalk.bean.course.teacher.TsNtTeacherOfCourseInfo;
import com.nativetalk.bean.dict.TsNtDictDeatil;
import com.nativetalk.bean.member.TdNtMember;
import com.nativetalk.bean.member.TdNtMemberFuns;
import com.nativetalk.bean.teacher.*;
import com.nativetalk.bean.website.TsNtWebSiteConfIndex;
import com.nativetalk.common.Constants;
import com.nativetalk.common.ValidationMessages;
import com.nativetalk.common.util.I18nMessages;
import com.nativetalk.common.util.MemcachedKey;
import com.nativetalk.common.util.MemcachedUtils;
import com.nativetalk.dao.TdNtTeacherDao;
import com.nativetalk.dao.TdNtTeacherLabelDao;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by lizhun on 16/1/9.
 */
@Service
public class TeacherSearchServiceImpl implements TeacherSearchService {
    private static Logger logger = Logger.getLogger(TeacherSearchServiceImpl.class);
    @Resource
    private TdNtTeacherDao tdNtTeacherDao;

    @Resource
    private TdNtTeacherLabelDao tdNtTeacherLabelDao;

    @Override
    public RetInfo findTeacherBalance(Integer tea_id) {
        String logInfo = this.getClass().getName() + ":findTeacherBalance:";
        logger.info("======" + logInfo + "begin======");
        RetInfo retInfo = new RetInfo();
        try {
            Map<String, Object> map = new HashMap<>();
            map.put("tea_balance", tdNtTeacherDao.findTdNtTeacherBalance(tea_id));
            map.put("rule", Constants.rule);
            System.out.println(Constants.rule);
            retInfo.setMark(ValidationMessages.getValue("MARKYES"));
            retInfo.setTip("获取余额成功");
            retInfo.setObj(map);
        } catch (Exception e) {
            retInfo.setMark(ValidationMessages.getValue("MARKERROR"));
            retInfo.setTip(ValidationMessages.getValue("TIPERROR"));
            logger.error(e.getMessage(), e);
        }
        logger.info("======" + logInfo + "end======");
        return retInfo;
    }

    @Override
    public RetInfo findTeacherIndex(Integer tea_id) {
        String logInfo = this.getClass().getName() + ":findTeacherIndex:";
        logger.info("======" + logInfo + "begin======");
        RetInfo retInfo = new RetInfo();
        try {
            retInfo.setMark(ValidationMessages.getValue("MARKYES"));
            retInfo.setTip("获取首页数据成功");
            TdNtTeacherIndex tdNtTeacherIndex = tdNtTeacherDao.findTdNtTeacherIndex(tea_id);
            tdNtTeacherIndex.setTea_total_balance(tdNtTeacherIndex.getTea_balance());
            tdNtTeacherIndex.setTea_total_times(tdNtTeacherIndex.getTea_times());

            retInfo.setObj(tdNtTeacherIndex);
        } catch (Exception e) {
            retInfo.setMark(ValidationMessages.getValue("MARKERROR"));
            retInfo.setTip(ValidationMessages.getValue("TIPERROR"));
            logger.error(e.getMessage(), e);
        }
        logger.info("======" + logInfo + "end======");
        return retInfo;
    }

    @Override
    public RetInfo findTeacherCourse(Page page) {
        String logInfo = this.getClass().getName() + ":findTeacherCourse:";
        logger.info("======" + logInfo + "begin======");
        RetInfo retInfo = new RetInfo();
        try {
            int currentPage = Integer.valueOf(page.getCurrentPage());
            int pageSize = page.getPageSize();//每页数据
            int totalPage;//总页数
            int totalRecord = tdNtTeacherDao.findTdNtTeacherCouIdSize(page);//总条数
            if (totalRecord > 0) {
                if (totalRecord % pageSize == 0) {
                    totalPage = totalRecord / pageSize;
                } else {
                    totalPage = (totalRecord / pageSize) + 1;
                }
                if (currentPage >= totalPage) {
                    currentPage = totalPage;
                }
                if (currentPage <= 1) {
                    currentPage = 1;
                }
                page.setCurrentPage((currentPage - 1) * pageSize);
                List<TdNtTeacherCourse> tdNtTeacherCourses = tdNtTeacherDao.findTdNtTeacherCouIdPage(page);
                Map<String, TsNtDictDeatil> tsNtDictDeatilsMap =
                        (Map<String, TsNtDictDeatil>) MemcachedUtils.get(MemcachedKey.tsNtDictDeatilsMap);
                for (int i = 0; i < tdNtTeacherCourses.size(); i++) {
                    if (tdNtTeacherCourses.get(i).getDict_id() != null) {
                        TsNtDictDeatil tsNtDictDeatil = tsNtDictDeatilsMap.get(tdNtTeacherCourses.get(i).getDict_id() + "");
                        tdNtTeacherCourses.get(i).setUniversity(tsNtDictDeatil.getCode_name());
                        tdNtTeacherCourses.get(i).setCountry(tsNtDictDeatilsMap.get(tsNtDictDeatil.getParent_id() + "").getCode_name());
                    } else {
                        TsNtDictDeatil tsNtDictDeatil = tsNtDictDeatilsMap.get("3");
                        tdNtTeacherCourses.get(i).setUniversity(tsNtDictDeatil.getCode_name());
                        tdNtTeacherCourses.get(i).setCountry(tsNtDictDeatilsMap.get(tsNtDictDeatil.getParent_id() + "").getCode_name());
                    }

                }

                Map<String, Object> obj = new HashMap<String, Object>();
                obj.put("tdNtTeacherCourses", tdNtTeacherCourses);
                obj.put("totalPage", totalPage);
                retInfo.setMark("0");
                retInfo.setTip("获取列表成功");
                retInfo.setObj(obj);
            } else {
                retInfo.setMark("1");
                retInfo.setTip("暂无老师");
            }

        } catch (Exception e) {
            retInfo.setMark(ValidationMessages.getValue("MARKERROR"));
            retInfo.setTip(ValidationMessages.getValue("TIPERROR"));
            logger.error(e.getMessage(), e);
        }
        logger.info("======" + logInfo + "end======");
        return retInfo;
    }

    @Override
    public RetInfo findTeacherStudy(Integer tea_id) {
        String logInfo = this.getClass().getName() + ":findTeacherStudy:";
        logger.info("======" + logInfo + "begin======");
        RetInfo retInfo = new RetInfo();
        try {

            TdNtTeacherCourse tdNtTeacherCourse = tdNtTeacherDao.findTeacherStudy(tea_id);

            if (tdNtTeacherCourse != null) {
                Map<String, TsNtDictDeatil> tsNtDictDeatilsMap =
                        (Map<String, TsNtDictDeatil>) MemcachedUtils.get(MemcachedKey.tsNtDictDeatilsMap);
                if (tdNtTeacherCourse.getDict_id() != null) {

                    TsNtDictDeatil tsNtDictDeatil = tsNtDictDeatilsMap.get(tdNtTeacherCourse.getDict_id() + "");
                    tdNtTeacherCourse.setUniversity(tsNtDictDeatil.getCode_name());
                    tdNtTeacherCourse.setCountry(tsNtDictDeatilsMap.get(tsNtDictDeatil.getParent_id() + "").getCode_name());
                } else {
                    TsNtDictDeatil tsNtDictDeatil = tsNtDictDeatilsMap.get("3");
                    tdNtTeacherCourse.setUniversity(tsNtDictDeatil.getCode_name());
                    tdNtTeacherCourse.setCountry(tsNtDictDeatilsMap.get(tsNtDictDeatil.getParent_id() + "").getCode_name());
                }
                retInfo.setMark("0");
                retInfo.setTip("成功");
                Map<String, Object> map = new HashMap<>();
                map.put("teacher", tdNtTeacherCourse);
                retInfo.setObj(map);
            } else {
                retInfo.setMark("1");
                retInfo.setTip("json数据错误");
            }

        } catch (Exception e) {
            retInfo.setMark(ValidationMessages.getValue("MARKERROR"));
            retInfo.setTip(ValidationMessages.getValue("TIPERROR"));
            logger.error(e.getMessage(), e);
        }
        logger.info("======" + logInfo + "end======");
        return retInfo;
    }

    @Override
    public RetInfo findTeacherCourseThree(Page page, TdNtMember tdNtMember) {
        String logInfo = this.getClass().getName() + ":findTeacherCourse:";
        logger.info("======" + logInfo + "begin======");
        RetInfo retInfo = new RetInfo();
        try {
            int currentPage = Integer.valueOf(page.getCurrentPage());
            int pageSize = page.getPageSize();//每页数据
            int totalPage;//总页数
            int totalRecord = tdNtTeacherDao.findTdNtTeacherCouIdSize(page);//总条数
            if (totalRecord > 0) {
                if (totalRecord % pageSize == 0) {
                    totalPage = totalRecord / pageSize;
                } else {
                    totalPage = (totalRecord / pageSize) + 1;
                }
                if (currentPage >= totalPage) {
                    currentPage = totalPage;
                }
                if (currentPage <= 1) {
                    currentPage = 1;
                }
                page.setCurrentPage((currentPage - 1) * pageSize);
                List<TdNtTeacherCollection> tdNtTeacherCourses = tdNtTeacherDao.findTdNtTeacherCouIdPageThree(page);
                Map<String, TsNtDictDeatil> tsNtDictDeatilsMap =
                        (Map<String, TsNtDictDeatil>) MemcachedUtils.get(MemcachedKey.tsNtDictDeatilsMap);

                for (int i = 0; i < tdNtTeacherCourses.size(); i++) {
                    //判断是否登录，没有登录默认为未收藏
                    if (tdNtMember == null) {
                        tdNtTeacherCourses.get(i).setCollection_flag("1");
                    } else {
                        Map<String, Object> obj = new HashMap<String, Object>();
                        obj.put("tea_id", tdNtTeacherCourses.get(i).getTea_id());
                        obj.put("memb_id", tdNtMember.getMemb_id());
                        //给查询到的老师教师信息添加收藏字段
                        String flag = tdNtTeacherDao.foundTdNtTeacherCollection(obj);
                        if (flag != null) {
                            tdNtTeacherCourses.get(i).setCollection_flag(flag);
                        } else {
                            tdNtTeacherCourses.get(i).setCollection_flag("1");
                        }

                        tdNtTeacherCourses.get(i).setCollection_flag(flag);
                    }
                    if (tdNtTeacherCourses.get(i).getDict_id() != null) {
                        TsNtDictDeatil tsNtDictDeatil = tsNtDictDeatilsMap.get(tdNtTeacherCourses.get(i).getDict_id() + "");
                        tdNtTeacherCourses.get(i).setUniversity(tsNtDictDeatil.getCode_name());
                        tdNtTeacherCourses.get(i).setCountry(tsNtDictDeatilsMap.get(tsNtDictDeatil.getParent_id() + "").getCode_name());
                    } else {
                        TsNtDictDeatil tsNtDictDeatil = tsNtDictDeatilsMap.get("3");
                        tdNtTeacherCourses.get(i).setUniversity(tsNtDictDeatil.getCode_name());
                        tdNtTeacherCourses.get(i).setCountry(tsNtDictDeatilsMap.get(tsNtDictDeatil.getParent_id() + "").getCode_name());
                    }

                }

                Map<String, Object> obj = new HashMap<String, Object>();
                obj.put("tdNtTeacherCourses", tdNtTeacherCourses);
                obj.put("totalPage", totalPage);
                retInfo.setMark("0");
                retInfo.setTip("获取列表成功");
                retInfo.setObj(obj);
            } else {
                retInfo.setMark("1");
                retInfo.setTip("暂无老师");
            }

        } catch (Exception e) {
            retInfo.setMark(ValidationMessages.getValue("MARKERROR"));
            retInfo.setTip(ValidationMessages.getValue("TIPERROR"));
            logger.error(e.getMessage(), e);
        }
        logger.info("======" + logInfo + "end======");
        return retInfo;
    }

    @Override
    public RetInfo findTeacherListTwo(Page page, TdNtMember tdNtMember) {
        String logInfo = this.getClass().getName() + ":findTeacherListTwo:";
        logger.info("======" + logInfo + "begin======");
        RetInfo retInfo = new RetInfo();
        try {
            int currentPage = Integer.valueOf(page.getCurrentPage());
            int pageSize = 9;//每页数据
            page.setPageSize(pageSize);
            int totalPage;//总页数
            int totalRecord = tdNtTeacherDao.findTdNtTeacherSize(page);//总条数
            if (totalRecord > 0) {
                if (totalRecord % pageSize == 0) {
                    totalPage = totalRecord / pageSize;
                } else {
                    totalPage = (totalRecord / pageSize) + 1;
                }
                if (currentPage >= totalPage) {
                    currentPage = totalPage;
                }
                if (currentPage <= 1) {
                    currentPage = 1;
                }
                page.setCurrentPage((currentPage - 1) * pageSize);
                List<TdNtTeacherCollection> tdNtTeacherCourses = tdNtTeacherDao.findTdNtTeacherPage(page);
                Map<String, TsNtDictDeatil> tsNtDictDeatilsMap =
                        (Map<String, TsNtDictDeatil>) MemcachedUtils.get(MemcachedKey.tsNtDictDeatilsMap);

                for (int i = 0; i < tdNtTeacherCourses.size(); i++) {
                    //判断是否登录，没有登录默认为未收藏
                    if (tdNtMember == null) {
                        tdNtTeacherCourses.get(i).setCollection_flag("1");
                    } else {
                        Map<String, Object> obj = new HashMap<String, Object>();
                        obj.put("tea_id", tdNtTeacherCourses.get(i).getTea_id());
                        obj.put("memb_id", tdNtMember.getMemb_id());
                        //给查询到的老师教师信息添加收藏字段
                        String flag = tdNtTeacherDao.foundTdNtTeacherCollection(obj);
                        if (flag != null) {
                            tdNtTeacherCourses.get(i).setCollection_flag(flag);
                        } else {
                            tdNtTeacherCourses.get(i).setCollection_flag("1");
                        }

                    }
                    if (tdNtTeacherCourses.get(i).getDict_id() != null) {
                        TsNtDictDeatil tsNtDictDeatil = tsNtDictDeatilsMap.get(tdNtTeacherCourses.get(i).getDict_id() + "");
                        tdNtTeacherCourses.get(i).setUniversity(tsNtDictDeatil.getCode_name());
                        tdNtTeacherCourses.get(i).setCountry(tsNtDictDeatilsMap.get(tsNtDictDeatil.getParent_id() + "").getCode_name());
                    } else {
                        TsNtDictDeatil tsNtDictDeatil = tsNtDictDeatilsMap.get("3");
                        tdNtTeacherCourses.get(i).setUniversity(tsNtDictDeatil.getCode_name());
                        tdNtTeacherCourses.get(i).setCountry(tsNtDictDeatilsMap.get(tsNtDictDeatil.getParent_id() + "").getCode_name());
                    }
                    /**
                     * 查找老师粉丝数
                     */
                    //获取该老师的粉丝数
                    int funsnumber = tdNtTeacherDao.findFunsSize(tdNtTeacherCourses.get(i).getTea_id());
                    tdNtTeacherCourses.get(i).setFans_size(funsnumber);
                }
                Map<String, Object> obj = new HashMap<String, Object>();
                obj.put("tdNtTeacherCourses", tdNtTeacherCourses);
                obj.put("totalPage", totalPage);
                /**
                 * 第一次查询给予随机老师
                 */
                if (currentPage == 1) {
                    List<TdNtTeacherRound> tdNtTeacherRounds = tdNtTeacherDao.findTdNtTeacherRound();
                    obj.put("tdNtTeacherRounds", tdNtTeacherRounds);
                    for (int i = 0; i < tdNtTeacherRounds.size(); i++) {
                        //判断是否登录，没有登录默认为未收藏
                        if (tdNtMember == null) {
                            tdNtTeacherCourses.get(i).setCollection_flag("1");
                        } else {
                            Map<String, Object> map = new HashMap<String, Object>();
                            map.put("tea_id", tdNtTeacherCourses.get(i).getTea_id());
                            map.put("memb_id", tdNtMember.getMemb_id());
                            //给查询到的老师教师信息添加收藏字段
                            String flag = tdNtTeacherDao.foundTdNtTeacherCollection(map);
                            if (flag != null) {
                                tdNtTeacherCourses.get(i).setCollection_flag(flag);
                            } else {
                                tdNtTeacherCourses.get(i).setCollection_flag("1");
                            }

                            tdNtTeacherRounds.get(i).setCollection_flag(flag);
                        }

                    }
                }
                retInfo.setMark("0");
                retInfo.setTip("获取列表成功");
                retInfo.setObj(obj);
            } else {
                retInfo.setMark("1");
                retInfo.setTip("暂无老师");
            }

        } catch (Exception e) {
            retInfo.setMark(ValidationMessages.getValue("MARKERROR"));
            retInfo.setTip(ValidationMessages.getValue("TIPERROR"));
            logger.error(e.getMessage(), e);
        }
        logger.info("======" + logInfo + "end======");
        return retInfo;
    }

    @Override
    public RetInfo findTeacherList(Page page, TdNtMember tdNtMember) {
        String logInfo = this.getClass().getName() + ":findTeacherList:";
        logger.info("======" + logInfo + "begin======");
        RetInfo retInfo = new RetInfo();
        try {
            int currentPage = Integer.valueOf(page.getCurrentPage());
            int pageSize = page.getPageSize();//每页数据
            int totalPage;//总页数
            int totalRecord = tdNtTeacherDao.findTdNtTeacherSize(page);//总条数
            if (totalRecord > 0) {
                if (totalRecord % pageSize == 0) {
                    totalPage = totalRecord / pageSize;
                } else {
                    totalPage = (totalRecord / pageSize) + 1;
                }
                if (currentPage >= totalPage) {
                    currentPage = totalPage;
                }
                if (currentPage <= 1) {
                    currentPage = 1;
                }
                page.setCurrentPage((currentPage - 1) * pageSize);
                List<TdNtTeacherCollection> tdNtTeacherCourses = tdNtTeacherDao.findTdNtTeacherPage(page);
                Map<String, TsNtDictDeatil> tsNtDictDeatilsMap =
                        (Map<String, TsNtDictDeatil>) MemcachedUtils.get(MemcachedKey.tsNtDictDeatilsMap);

                for (int i = 0; i < tdNtTeacherCourses.size(); i++) {
                    //判断是否登录，没有登录默认为未收藏
                    if (tdNtMember == null) {
                        tdNtTeacherCourses.get(i).setCollection_flag("1");
                    } else {
                        Map<String, Object> obj = new HashMap<String, Object>();
                        obj.put("tea_id", tdNtTeacherCourses.get(i).getTea_id());
                        obj.put("memb_id", tdNtMember.getMemb_id());
                        //给查询到的老师教师信息添加收藏字段
                        String flag = tdNtTeacherDao.foundTdNtTeacherCollection(obj);
                        if (flag != null) {
                            tdNtTeacherCourses.get(i).setCollection_flag(flag);
                        } else {
                            tdNtTeacherCourses.get(i).setCollection_flag("1");
                        }

                    }
                    if (tdNtTeacherCourses.get(i).getDict_id() != null) {
                        TsNtDictDeatil tsNtDictDeatil = tsNtDictDeatilsMap.get(tdNtTeacherCourses.get(i).getDict_id() + "");
                        tdNtTeacherCourses.get(i).setUniversity(tsNtDictDeatil.getCode_name());
                        tdNtTeacherCourses.get(i).setCountry(tsNtDictDeatilsMap.get(tsNtDictDeatil.getParent_id() + "").getCode_name());
                    } else {
                        TsNtDictDeatil tsNtDictDeatil = tsNtDictDeatilsMap.get("3");
                        tdNtTeacherCourses.get(i).setUniversity(tsNtDictDeatil.getCode_name());
                        tdNtTeacherCourses.get(i).setCountry(tsNtDictDeatilsMap.get(tsNtDictDeatil.getParent_id() + "").getCode_name());
                    }
                }
                Map<String, Object> obj = new HashMap<String, Object>();
                obj.put("tdNtTeacherCourses", tdNtTeacherCourses);
                obj.put("totalPage", totalPage);
                retInfo.setMark("0");
                retInfo.setTip("获取列表成功");
                retInfo.setObj(obj);
            } else {
                retInfo.setMark("1");
                retInfo.setTip("暂无老师");
            }
        } catch (Exception e) {
            retInfo.setMark(ValidationMessages.getValue("MARKERROR"));
            retInfo.setTip(ValidationMessages.getValue("TIPERROR"));
            logger.error(e.getMessage(), e);
        }
        logger.info("======" + logInfo + "end======");
        return retInfo;
    }

    @Override
    public RetInfo findTeacherInfo(Integer tea_id, TdNtMember tdNtMember) {
        String logInfo = this.getClass().getName() + ":findTeacherInfo:";
        logger.info("======" + logInfo + "begin======");
        RetInfo retInfo = new RetInfo();
        Map<String, Object> map = new HashMap<>();
        try {
            //获取教师详细的详细信息
            TdNtTeacherCourse tdNtTeacherCourse = tdNtTeacherDao.findTeacherStudy(tea_id);
            if (tdNtTeacherCourse != null) {
                Map<String, TsNtDictDeatil> tsNtDictDeatilsMap =
                        (Map<String, TsNtDictDeatil>) MemcachedUtils.get(MemcachedKey.tsNtDictDeatilsMap);
                Map<String, TsNtCourseInfoDetail> tsNtCourseInfoDetailMap =
                        (Map<String, TsNtCourseInfoDetail>) MemcachedUtils.get(MemcachedKey.tsNtCourseInfoDetailMap);
                if (tdNtTeacherCourse.getDict_id() != null) {

                    TsNtDictDeatil tsNtDictDeatil = tsNtDictDeatilsMap.get(tdNtTeacherCourse.getDict_id() + "");
                    tdNtTeacherCourse.setUniversity(tsNtDictDeatil.getCode_name());
                    tdNtTeacherCourse.setCountry(tsNtDictDeatilsMap.get(tsNtDictDeatil.getParent_id() + "").getCode_name());
                } else {
                    TsNtDictDeatil tsNtDictDeatil = tsNtDictDeatilsMap.get("3");
                    tdNtTeacherCourse.setUniversity(tsNtDictDeatil.getCode_name());
                    tdNtTeacherCourse.setCountry(tsNtDictDeatilsMap.get(tsNtDictDeatil.getParent_id() + "").getCode_name());
                }
                //获取cate_id
                List<TsNtCourseInfo> courseInfoList = tdNtTeacherDao.findTeacherOpenCourseInfo(tea_id);
                List<TsNtTeacherOfCourseInfo> tsNtTeacherOfCourseInfoList = new ArrayList<>();
                if (courseInfoList != null && courseInfoList.size() > 0) {
                    for (int j = 0; j < courseInfoList.size(); j++) {
                        //获取教师的课程信息
                        TsNtTeacherOfCourseInfo tsNtTeacherOfCourseInfo = new TsNtTeacherOfCourseInfo();
                        TsNtCourseInfoDetail tsNtCourseInfoDetail = tsNtCourseInfoDetailMap.get(courseInfoList.get(j).getCou_id().toString());
                        tsNtTeacherOfCourseInfo.setCou_id(tsNtCourseInfoDetail.getCou_id());
                        tsNtTeacherOfCourseInfo.setCate_id(tsNtCourseInfoDetail.getCate_id());
                        tsNtTeacherOfCourseInfo.setCou_name(tsNtCourseInfoDetail.getCou_name());
                        tsNtTeacherOfCourseInfo.setStudy_size(tsNtCourseInfoDetail.getStudy_size());
                        tsNtTeacherOfCourseInfo.setBanner_img_url(tsNtCourseInfoDetail.getStand());
                        tsNtTeacherOfCourseInfoList.add(tsNtTeacherOfCourseInfo);
                    }
                    if (tsNtTeacherOfCourseInfoList == null) {
                        map.put("course", tsNtTeacherOfCourseInfoList);
                    } else if (tsNtTeacherOfCourseInfoList.size() > 4) {
                        map.put("course", tsNtTeacherOfCourseInfoList.subList(0, 4));
                    } else {
                        map.put("course", tsNtTeacherOfCourseInfoList);
                    }
                }
                String collection_flag = "1";
                //判断是否登录，没有登录默认为未收藏
                if (tdNtMember != null) {
                    Map<String, Object> obj = new HashMap<String, Object>();
                    obj.put("tea_id", tea_id);
                    obj.put("memb_id", tdNtMember.getMemb_id());
                    String flag = tdNtTeacherDao.foundTdNtTeacherCollection(obj);
                    if (flag != null) {
                        collection_flag = flag;
                    }
                }
                map.put("collection_flag", collection_flag);
                //获取教师的评价信息
                List<TdNtCommentCouse> tdNtCommentCouse = tdNtTeacherDao.findTdNtTeacherComments(tea_id);
                int totalRecord;
                if (tdNtCommentCouse != null) {
                    totalRecord = tdNtCommentCouse.size();//总条数
                } else {
                    totalRecord = 0;//总条数
                }

                int totalPage;//总页数
                int pageSize = 10;
                int currentPage = 1;

                if (totalRecord % pageSize == 0) {
                    totalPage = totalRecord / pageSize;
                } else {
                    totalPage = (totalRecord / pageSize) + 1;
                }
                if (currentPage >= totalPage) {
                    currentPage = totalPage;
                }
                if (tdNtCommentCouse == null) {
                    map.put("comment", tdNtCommentCouse);
                } else if (tdNtCommentCouse.size() > 10) {
                    map.put("comment", tdNtCommentCouse.subList(0, 10));
                } else {
                    map.put("comment", tdNtCommentCouse);
                }
                map.put("commentSize", tdNtCommentCouse.size());
                map.put("totalPage", totalPage);
                //获取该老师的粉丝数
                int funsnumber = tdNtTeacherDao.findFunsSize(tea_id);

                retInfo.setMark("0");
                retInfo.setTip("成功");
                map.put("teacher", tdNtTeacherCourse);
                map.put("fansnumber", funsnumber);
                map.put("teacher_id", "testteacher");
                Map<String, TsNtWebSiteConfIndex> tsNtWebSiteConfIndexMap = (Map<String, TsNtWebSiteConfIndex>) MemcachedUtils.get(MemcachedKey.tsNtWebSiteConfIndexMap);
                map.put("share", tsNtWebSiteConfIndexMap.get("27").getData_value());
                map.put("share_name", tsNtWebSiteConfIndexMap.get("28").getData_value());
                map.put("share_url", Constants.share_teacher_url + tdNtTeacherCourse.getTea_id());
                map.put("share_picutre", "http://file.waijiaojun.com/" + "nativetalk/WechatIMG2.png");
                map.put("share_content", tsNtWebSiteConfIndexMap.get("28").getData_value());
                retInfo.setObj(map);
            } else {
                retInfo.setMark("1");
                retInfo.setTip("json数据错误");
            }

        } catch (Exception e) {
            retInfo.setMark(ValidationMessages.getValue("MARKERROR"));
            retInfo.setTip(ValidationMessages.getValue("TIPERROR"));
            logger.error(e.getMessage(), e);
        }
        logger.info("======" + logInfo + "end======");
        return retInfo;
    }

    @Override
    public RetInfo findlistCommentInfo(Page page) {
        String logInfo = this.getClass().getName() + ":findlistCommentInfo:";
        logger.info("======" + logInfo + "begin======");
        RetInfo retInfo = new RetInfo();
        try {
            int currentPage = Integer.valueOf(page.getCurrentPage());
            int pageSize = page.getPageSize();//每页数据
            int totalPage;//总页数
            int totalRecord = tdNtTeacherDao.findTdNtTeacherCommentsSize(Integer.decode((String) page.getObj()));//总条数
            if (totalRecord > 0) {
                if (totalRecord % pageSize == 0) {
                    totalPage = totalRecord / pageSize;
                } else {
                    totalPage = (totalRecord / pageSize) + 1;
                }
                if (currentPage >= totalPage) {
                    currentPage = totalPage;
                }
                if (currentPage <= 1) {
                    currentPage = 1;
                }
                page.setCurrentPage((currentPage - 1) * pageSize);
                List<TdNtCommentCouse> tdNtCommentCouse = tdNtTeacherDao.findTdNtTeacherCommentsPage(page);
                Map<String, Object> obj = new HashMap<String, Object>();
                obj.put("comment", tdNtCommentCouse);
                obj.put("totalPage", totalPage);
                retInfo.setMark("0");
                retInfo.setTip("获取评论成功");
                retInfo.setObj(obj);
            } else {
                retInfo.setMark("1");
                retInfo.setTip("暂无评论");
            }
        } catch (Exception e) {
            retInfo.setMark(ValidationMessages.getValue("MARKERROR"));
            retInfo.setTip(ValidationMessages.getValue("TIPERROR"));
            logger.error(e.getMessage(), e);
        }
        logger.info("======" + logInfo + "end======");
        return retInfo;
    }


    @Override
    public RetInfo findfunslist(Page page) {
        String logInfo = this.getClass().getName() + ":findfunslist:";
        logger.info("======" + logInfo + "begin======");
        RetInfo retInfo = new RetInfo();
        try {
            int currentPage = Integer.valueOf(page.getCurrentPage());
            int pageSize = page.getPageSize();//每页数据
            int totalPage;//总页数
            int totalRecord = tdNtTeacherDao.findFunsSize(Integer.parseInt((String) page.getObj()));//总条数
            if (totalRecord > 0) {
                if (totalRecord % pageSize == 0) {
                    totalPage = totalRecord / pageSize;
                } else {
                    totalPage = (totalRecord / pageSize) + 1;
                }
                if (currentPage >= totalPage) {
                    currentPage = totalPage;
                }
                if (currentPage <= 1) {
                    currentPage = 1;
                }
                page.setCurrentPage((currentPage - 1) * pageSize);

                List<TdNtMemberFuns> tdNtMemberFunsList = tdNtTeacherDao.findfunslistPage(page);
                Map<String, Object> obj = new HashMap<String, Object>();
                obj.put("funsList", tdNtMemberFunsList);
                obj.put("totalPage", totalPage);
                obj.put("member", Constants.member);
                retInfo.setMark("0");
                retInfo.setTip("获取粉丝列表成功");
                retInfo.setObj(obj);
            } else {
                Map<String, Object> obj = new HashMap<String, Object>();
                obj.put("funsList", new ArrayList<TdNtMemberFuns>());
                obj.put("totalPage", 0);
                obj.put("member", Constants.member);
                retInfo.setMark("0");
                retInfo.setMark("0");
                retInfo.setTip(I18nMessages.en.getString("no.content.to.show"));
                retInfo.setObj(obj);
            }
        } catch (Exception e) {
            retInfo.setMark(ValidationMessages.getValue("MARKERROR"));
            retInfo.setTip(ValidationMessages.getValue("TIPERROR"));
            logger.error(e.getMessage(), e);
        }
        logger.info("======" + logInfo + "end======");
        return retInfo;
    }

    @Override
    public RetInfo findAttentionlist(Page page, TdNtMember tdNtMember) {
        String logInfo = this.getClass().getName() + ":findAttentionlist:";
        logger.info("======" + logInfo + "begin======");
        RetInfo retInfo = new RetInfo();
        try {
            if (tdNtMember == null) {
                retInfo.setMark("101");
                retInfo.setTip("用户未登陆");
            } else {
                page.setObj(tdNtMember.getMemb_id());
                int currentPage = Integer.valueOf(page.getCurrentPage());
                int pageSize = page.getPageSize();//每页数据
                int totalPage;//总页数
                int totalRecord = tdNtTeacherDao.findAttentionlistSize(tdNtMember.getMemb_id());//总条数
                if (totalRecord > 0) {
                    if (totalRecord % pageSize == 0) {
                        totalPage = totalRecord / pageSize;
                    } else {
                        totalPage = (totalRecord / pageSize) + 1;
                    }
                    if (currentPage >= totalPage) {
                        currentPage = totalPage;
                    }
                    if (currentPage <= 1) {
                        currentPage = 1;
                    }
                    page.setCurrentPage((currentPage - 1) * pageSize);
                    List<TdNtTeacherCollectionOnline> tdNtTeacherCourses = tdNtTeacherDao.findAttentionlistPage(page);
                    Map<String, TsNtDictDeatil> tsNtDictDeatilsMap =
                            (Map<String, TsNtDictDeatil>) MemcachedUtils.get(MemcachedKey.tsNtDictDeatilsMap);
                    if (tdNtTeacherCourses.size() != 0) {
                        for (int i = 0; i < tdNtTeacherCourses.size(); i++) {
                            Map<String, Object> obj = new HashMap<String, Object>();
                            obj.put("tea_id", tdNtTeacherCourses.get(i).getTea_id());
                            obj.put("memb_id", tdNtMember.getMemb_id());
                            //给查询到的老师教师信息添加是否上线字段
                            String flag = tdNtTeacherDao.foundTdNtTeacherOnline(obj);
                            tdNtTeacherCourses.get(i).setGo_online(flag);
                            if (tdNtTeacherCourses.get(i).getDict_id() != null) {
                                TsNtDictDeatil tsNtDictDeatil = tsNtDictDeatilsMap.get(tdNtTeacherCourses.get(i).getDict_id() + "");
                                tdNtTeacherCourses.get(i).setUniversity(tsNtDictDeatil.getCode_name());
                                tdNtTeacherCourses.get(i).setCountry(tsNtDictDeatilsMap.get(tsNtDictDeatil.getParent_id() + "").getCode_name());
                            } else {
                                TsNtDictDeatil tsNtDictDeatil = tsNtDictDeatilsMap.get("3");
                                tdNtTeacherCourses.get(i).setUniversity(tsNtDictDeatil.getCode_name());
                                tdNtTeacherCourses.get(i).setCountry(tsNtDictDeatilsMap.get(tsNtDictDeatil.getParent_id() + "").getCode_name());
                            }
                            /**
                             * 查找老师系统标签
                             */
                            Map<String, Object> params = new HashMap<>();
                            params.put("tea_id", tdNtTeacherCourses.get(i).getTea_id());
                            params.put("lab_type", 1);
                            tdNtTeacherCourses.get(i).setLabels(tdNtTeacherLabelDao.findTdNtTeacherListTeaIdAndType(params));
                            /**
                             * 查找老师粉丝数
                             */
                            int funsnumber = tdNtTeacherDao.findFunsSize(tdNtTeacherCourses.get(i).getTea_id());
                            tdNtTeacherCourses.get(i).setFans_size(funsnumber);
                        }
                    }
                    Map<String, Object> obj = new HashMap<String, Object>();
                    obj.put("attentionList", tdNtTeacherCourses);
                    obj.put("totalPage", totalPage);
                    retInfo.setMark("0");
                    retInfo.setTip("获取用户关注列表成功");
                    retInfo.setObj(obj);
                } else {
                    retInfo.setMark("1");
                    retInfo.setTip("暂无关注老师");
                }
            }
        } catch (Exception e) {
            retInfo.setMark(ValidationMessages.getValue("MARKERROR"));
            retInfo.setTip(ValidationMessages.getValue("TIPERROR"));
            logger.error(e.getMessage(), e);
        }
        logger.info("======" + logInfo + "end======");
        return retInfo;
    }

    @Override
    public RetInfo findTeacherIndextwo(Integer tea_id) {
        String logInfo = this.getClass().getName() + ":findTeacherIndextwo:";
        logger.info("======" + logInfo + "begin======");
        RetInfo retInfo = new RetInfo();
        try {
            retInfo.setMark(ValidationMessages.getValue("MARKYES"));
            retInfo.setTip("获取首页数据成功");
            TdNtTeacherIndex tdNtTeacherIndex = tdNtTeacherDao.findTdNtTeacherIndex(tea_id);
            TdNtTeacherIndexN tdNtTeacherIndexN = new TdNtTeacherIndexN();
            tdNtTeacherIndexN.setState(tdNtTeacherIndex.getState());
            tdNtTeacherIndexN.setTea_balance(tdNtTeacherIndex.getTea_balance());
            tdNtTeacherIndexN.setTea_head_portrait(tdNtTeacherIndex.getTea_head_portrait());
            tdNtTeacherIndexN.setTea_id(tea_id);
            tdNtTeacherIndexN.setTea_invite_code(tdNtTeacherIndex.getTea_invite_code());
            tdNtTeacherIndexN.setTea_islock(tdNtTeacherIndex.getTea_islock());
            tdNtTeacherIndexN.setTea_name(tdNtTeacherIndex.getTea_name());
            tdNtTeacherIndexN.setTea_score(tdNtTeacherIndex.getTea_score());
            tdNtTeacherIndexN.setTea_times(tdNtTeacherIndex.getTea_times());
            tdNtTeacherIndexN.setTea_total_balance(tdNtTeacherIndex.getTea_total_balance());
            tdNtTeacherIndexN.setTea_total_times(tdNtTeacherIndex.getTea_total_times());
            Map<String, Object> map = new HashMap<>();
            map.put("tdNtTeacherIndex", tdNtTeacherIndexN);
            Map<String, TsNtWebSiteConfIndex> tsNtWebSiteConfIndexMap = (Map<String, TsNtWebSiteConfIndex>) MemcachedUtils.get(MemcachedKey.tsNtWebSiteConfIndexMap);
            int totalRecord = tdNtTeacherDao.findFunsSize(tea_id);
            map.put("funs_size", totalRecord);
            map.put("share", tsNtWebSiteConfIndexMap.get("27").getData_value());
            map.put("share_name", tsNtWebSiteConfIndexMap.get("28").getData_value());
            map.put("share_url", Constants.share_teacher_url + tea_id);
            map.put("share_picutre", Constants.DOMAIN + tdNtTeacherIndex.getTea_head_portrait());
            map.put("share_content", tsNtWebSiteConfIndexMap.get("28").getData_value());
            retInfo.setObj(map);
        } catch (Exception e) {
            retInfo.setMark(ValidationMessages.getValue("MARKERROR"));
            retInfo.setTip(ValidationMessages.getValue("TIPERROR"));
            logger.error(e.getMessage(), e);
        }
        logger.info("======" + logInfo + "end======");
        return retInfo;
    }

    public TdNtTeacherResult findByTeaId(Integer tea_id) {
        return tdNtTeacherDao.findTeacherByTeaId(tea_id);
    }
}
